/**
 * https://leetcode.cn/problems/koko-eating-bananas/submissions/566032939/
 * 875. 爱吃香蕉的珂珂
 * medium 陈贝纯 2024.09.19
 * 二分搜索
 */

class Solution {
public:
    typedef long  long ll;
    int n;
    bool check(ll mid,vector<int>&  piles,int h){
        for(int i=0;i<n;++i)
            h-=ceil(piles[i]*1.0/mid);
            return h>=0;
    }
    int minEatingSpeed(vector<int>& piles, int h) {
        n=piles.size();
        int l=1;
        int r=1e9;
        int ans=0;
        while(l<=r){
            ll mid=l+(r-l)/2;
            if(check(mid,piles,h)){
                ans=mid;
                r=mid-1;
            }
            else
            l=mid+1;
        }
        return ans;
    }
};